﻿using System;
using Glue;
using Xunit;

namespace GlueTests.RelationsVerificationTests
{
    public class When_property_is_flattened
    {
        private readonly Mapping<DomainPerson, GuiPerson> personMapping;
        private readonly IRelationsVerification verifier;

        public class DomainPerson {public DomainAddress Address { get; set; }}
        public class DomainAddress {public String City { get; set; }}

        public class GuiPerson {public String City { get; set; }}

        public When_property_is_flattened()
        {
            personMapping = new Mapping<DomainPerson, GuiPerson>();
            var addressMapping = new Mapping<DomainAddress, GuiPerson>();
            addressMapping.AutoRelateEqualNames();
            
            personMapping.Flatten(domain => domain.Address, addressMapping);
            
            verifier = personMapping.GetRelationsVerification();
        }

        [Fact]
        public void Should_verify_towards_flattened_type()
        {
            verifier.AssertAllPropertiesRelated<GuiPerson>();
        }

        [Fact]
        public void Should_verify_towards_nested_type()
        {
            verifier.AssertAllPropertiesRelated<DomainPerson>();
        }
    }
}
